/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package IU;

import DAO.CPerroDAO;
import VO.CPerro;
import javax.swing.JOptionPane;

/**
 *
 * @author langeblanc
 */
public class jIFRegistrarPerro extends javax.swing.JInternalFrame {

    /**
     * Creates new form jIFRegistrarPerro
     */
    public jIFRegistrarPerro() {
        
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPRegistroPerro = new javax.swing.JPanel();
        jLCodPerro = new javax.swing.JLabel();
        jLNomPerro = new javax.swing.JLabel();
        jBGuardar = new javax.swing.JButton();
        jTFCodPerro = new javax.swing.JTextField();
        jTFNomPerro = new javax.swing.JTextField();

        jLCodPerro.setText("Código del Perro");

        jLNomPerro.setText("Nombre");

        jBGuardar.setText("Registrar");
        jBGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBGuardarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPRegistroPerroLayout = new javax.swing.GroupLayout(jPRegistroPerro);
        jPRegistroPerro.setLayout(jPRegistroPerroLayout);
        jPRegistroPerroLayout.setHorizontalGroup(
            jPRegistroPerroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPRegistroPerroLayout.createSequentialGroup()
                .addGroup(jPRegistroPerroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPRegistroPerroLayout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addGroup(jPRegistroPerroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTFCodPerro, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTFNomPerro, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLNomPerro)
                            .addComponent(jLCodPerro)))
                    .addGroup(jPRegistroPerroLayout.createSequentialGroup()
                        .addGap(43, 43, 43)
                        .addComponent(jBGuardar)))
                .addContainerGap(29, Short.MAX_VALUE))
        );
        jPRegistroPerroLayout.setVerticalGroup(
            jPRegistroPerroLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPRegistroPerroLayout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addComponent(jLCodPerro)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTFCodPerro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(5, 5, 5)
                .addComponent(jLNomPerro)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTFNomPerro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
                .addComponent(jBGuardar)
                .addGap(23, 23, 23))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(jPRegistroPerro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(28, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(36, 36, 36)
                .addComponent(jPRegistroPerro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(55, Short.MAX_VALUE))
        );

        getAccessibleContext().setAccessibleParent(this);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBGuardarActionPerformed
        // TODO add your handling code here:
        CPerro miPerro = new CPerro();
        
        miPerro.setCodPerro(Integer.parseInt(jTFCodPerro.getText()));
        miPerro.setNombrePerro(jTFNomPerro.getText());
        
        CPerroDAO perroDAO = new CPerroDAO();
        
        try {
            perroDAO.insertar(miPerro);
            JOptionPane.showMessageDialog(this, "Se ha registrado su perro");
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error al registrar el perro " + ex.getMessage());
        }
    }//GEN-LAST:event_jBGuardarActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBGuardar;
    private javax.swing.JLabel jLCodPerro;
    private javax.swing.JLabel jLNomPerro;
    private javax.swing.JPanel jPRegistroPerro;
    private javax.swing.JTextField jTFCodPerro;
    private javax.swing.JTextField jTFNomPerro;
    // End of variables declaration//GEN-END:variables
}
